package com.njym.java.security.app.rest;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.njym.java.security.app.biz.LecturerBiz;
import com.njym.java.security.app.entity.Lecturer;
import com.njym.java.security.app.entity.TravelHero;
import com.njym.java.security.common.rest.BaseController;
import com.njym.java.security.common.util.ResponseUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import tk.mybatis.mapper.entity.Example;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("lecturer")
public class LecturerController extends BaseController<LecturerBiz,Lecturer> {

    @RequestMapping(value = "/getList", method = RequestMethod.GET)
    @ResponseBody
    public Object getList(@RequestParam(defaultValue = "10") int limit,
        @RequestParam(defaultValue = "1") int page, String province, String name, String pname){
        if("undefined".equals(province)){
            province = "";
        }
        if("undefined".equals(name)){
            name = "";
        }
        List<Lecturer> list = baseBiz.queryList(province, name, pname, page, limit);
        long total = PageInfo.of(list).getTotal();
        int totalPages =  (int) Math.ceil((double) total / limit);
        Map<String, Object> data = new HashMap<>(3);
        data.put("list", list);
        data.put("total", total);
        data.put("totalPages", totalPages);
        return ResponseUtil.ok(data);
    }
}